<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<%@ include file="/static/commons/jquery-easyui.jsp"%>
<html >
	 <head>
 		<title>${title }</title>
 		 <link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/main.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/searchBtn.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/searchCondition.css" />
	 
 		<script type="text/javascript" src="${ctx}/static/scripts/check_all.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/set_select.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/waiting.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/crud.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/common.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/util.js"></script>
  </head>
  
  <body onload="init()">
  		<form action="${ctx}/user/list" method="post">
  			<input type="hidden" name="RequestVerificationToken" value="${RequestVerificationToken}" />
  			<div class="width_100 group_box">
				<div class="group_search width_100">
					<vvise:select ifTree="true" id="deptId" name="p_deptId" sqlname="getDeptByUser" sqlparam="${LoginUser.deptId}" displayText="归属部门" ifSearch="true"   />
					<vvise:select id="status" name="p_status" sqlname="getCodeData" sqlparam="data_status" displayText="状态" ifSearch="true"   />
					<vvise:searchInput id="userId" name="p_userId" displayText="帐号" />
					<vvise:searchInput id="userName" name="p_userName" displayText="姓名" />
               	 	<div class="clear_both"></div>
				</div>
				<vvise:funMenu menuId="${menuId}" />
			</div>
        </form>
        <div class="listFrame">
        	<iframe name="listFrame" id="listFrame" frameBorder="0"
				scrolling="auto" style="width: 100%;height: 100%;"></iframe>
        </div>
  </body>
  <script type="text/javascript">
  		var headers = {};
		headers['__RequestVerificationToken'] = "${RequestVerificationToken}";
		//回车事件
		document.onkeydown = keyKistener;
		function keyKistener(e){
			e = e ? e:event;
			if(e.keyCode == 13){
				try{
					search();
				}catch(e){}
			}
		}
		function init(){
			set_iframe_h();
			$(window).resize(function(){
				set_iframe_h();
			});
			search();
		}
		//设置ifream 高度
		function set_iframe_h(){
			var win_height  = $(window).height();
			var func_line_h = $('.group_box').outerHeight(true);
			var list_height = win_height - func_line_h;
			$('.listFrame').css('height',list_height-10);
		}
		function search(){
			waiting();
			document.forms[0].target = "listFrame";
			document.forms[0].submit();
		}
		
		function create(userId){
			var pp = parent;
			if(parent.isEmpty(userId)){
				userId = "";
			}
			doCreate("用户信息",pp.width2,380,"${ctx}/user/edit?p_userId="+userId);
		}
	
		function save(){
			var pp = parent;
			var editFrame = pp.winFrame;
			var userId = editFrame.$('#userId').val();
			var ouserId = editFrame.$('#old_userId').val();
			
			if(!pp.validData("userId","请输入用户帐号！"))
				return;
			if(isEmpty(ouserId)){
				var flag = executeAjaxBySync('${ctx}/user/checkName','userId='+userId);
				if(flag == 'ERROR'){
					pp.alertMsg('用户账户已存在，请重新输入！','warning',function(){
						try{
						 	editFrame.$('#userId').focus();
					 	 }catch(e){}
					});
					return;
				}
			}	
			
			if(!pp.validData("userName","请输入用户姓名！"))
				return;
				
			if(!pp.validData("password","请输入登录密码！"))
				return;
			
			if(pp.trim(editFrame.$('#password').val()) != pp.trim(editFrame.$('#password2').val())){
				pp.$.messager.alert('操作提示',"两次密码输入的不一致！","warning",function(){
					try{
					 	editFrame.$('#password2').focus();
				 	 }catch(e){}
				});
				return;
			}
			
			if(!pp.validData("deptId","请选择归属部门！",3))
				return;
				
			
			doSave("${ctx}/user/save",userId);
		}
		
		function view(userId){
			var pp = parent;
			doView("用户信息",pp.width2,380,"${ctx}/user/edit?p_userId="+userId+"&view=view");
		}
		
		function updateStatus(flag){
			var pp = parent;
			var ids = "";
			var ecForm = listFrame.document.all.ec;
			if(!checkSelect(ecForm.id,true))
				return;
			ids = get_checkbox_values(ecForm.id,',');
			
			var optMsg = "状态修改成功！";
			var msgVal = "启用";
			if(flag == 2)
				msgVal = "停用";
			if(flag == 3){
				msgVal = "删除";
				optMsg = "删除成功！";
			}
			pp.confirmMsg("确定要"+ msgVal +"吗？",function(){
				var urls = "${ctx}/user/updateStatus";
			    var params = "ids="+ids;
			    params += "&status="+flag;
			    executeAjax(urls,params,function(data){
				    if(data != 'error'){
				    	pp.$.messager.alert('操作提示', optMsg, "info",function(){
				    		listRefresh();
				    	});
					}else{
						pp.$.messager.alert('操作提示',"操作失败！","error");
					}
			    });
			});
			
			
		}
	</script>
</html>